#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <getopt.h>

#include "kylin-verify.h"
#include "encrypt.h"
#include "dict.h"
#include "date.h"
#include "hwid.h"
#include "kylin-activation.h"
#include "kylin-ukey.h"

/*
 * kylin_activation_print_result_message, print message according to result number
 */
extern void kylin_activation_print_result_message(int result);

const char help_info[] = {
"Usage: kylin_ukey_dump [options]\n"
"Options:\n"
"        --all, -a        Display all information.\n"
"        --encrypt, -e    Encrypt information.\n"
"        --help, -h       Show this message.\n"
"\n"
};

static struct option long_options[] = 
{
	{"all", 0, 0, 'a'},
	{"encrypt", 0, 0, 'e'},
	{"help", 0, 0, 'h'},
	{0, 0, 0, 0},
};

int main(int argc, char** argv)
{

	int ret = -1;
	int encrypt = 0;
	int display_all = 0;
	int c;

	while(1)
	{
		int option_index = 0;
		c = getopt_long(argc, argv, "aeh", long_options, &option_index);
		if(c == -1)
			break;

		switch (c)
		{
			case 0:
				if(0 == option_index)
				{
					display_all = 1;
					break;
				}
				if(1 == option_index)
				{
					encrypt = 1;
					break;
				}
				if(2 == option_index)
				{
					fprintf(stderr, "%s", help_info);
					exit(0);
				}
				break;
			case 'a':
				display_all = 1;
				break;
			case 'e':
				encrypt = 1;
				break;
			case 'h':
				fprintf(stderr, "%s", help_info);
				exit(0);
			case '?':
				exit(-1);
			default:
				fprintf(stderr, "There is some invalid argument.\n");
				exit(-1);
				
		}
	}

	ret = ukey_dump(stdout, encrypt, display_all);
	if(ret != NO_ERROR)
		kylin_activation_print_result_message(ret);

	exit(ret);
}
